<?php

class LlenarcombosController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
     	# $this->_helper->layout->disableLayout ();
		//$this->_helper->viewRenderer->setNoRender ();
		 echo "indexAction";
	  
    }
	
	public function combosectorAction(){
		$this->_helper->getHelper ( 'ajaxContext' )->initContext ();
		
		if ($this->getRequest ()->isXmlHttpRequest ()) {
			$this->_helper->viewRenderer->setNoRender ();
			$this->_helper->layout->disableLayout ();
			
			$upper = new Zend_Filter_StringToUpper();
			$upper->setEncoding('UTF-8');
			$cod_almac = $this->_request->getPost('cod_almacen');
			$cn = new Model_Data();
			$parameter[]=array("@pcod_sector",'');
			$parameter[]=array("@pdesc_sector",'');
			$parameter[]=array("@pest_sector",'1');
			$parameter[]=array("@pcod_almacen",$cod_almac);
			/*@pcod_sector
			@pdesc_sector
			@pest_sector
			@pcod_almacen*/	
			$result_bus = $cn ->ejec_store_procedura_sql("MSector_list", $parameter);
			$pintar = New Libreria_Pintar();
			if (count($result_bus)!=0){
			for ($x=0;$x<count($result_bus);$x++)
    			$cbo[] = array($result_bus[$x][0],$result_bus[$x][3]);
			
			$val[] = array('#cbocod_sector',$pintar->ContenidoCombo($cbo,'null'),'html');
			$pintar->PintarValor($val);
			}else{
				echo "<script>$('#cbocod_sector').html('');</script>";
			}
		}
	}

	public function combocombinahtmlAction(){
		
		//$this->_helper->getHelper ( 'ajaxContext' )->initContext ();
		
		//if ($this->getRequest ()->isXmlHttpRequest ()) {
			$this->_helper->viewRenderer->setNoRender ();
			$this->_helper->layout->disableLayout ();
			
			//$bq = $this->_request->getPost('term');
			$bq = strtolower($_GET["term"]);
			//if (!$bq) return;
			$cn = new Model_Data();
			$pintar = New Libreria_Pintar();
			$CBparameter[]=array("@pcod_combin","");
			$CBparameter[]=array("@pdescripcion",'');
			$CBparameter[]=array("@pest_combin",'');//Poner en 1!!!
			$CBparameter[]=array("@cod_matprima",$bq);//Poner en 1!!!

			$CBresult_bus = $cn ->ejec_store_procedura_sql("Mcombinaciones_list", $CBparameter);

			if(count($CBresult_bus)=='0'){
				echo '<option value="9999999999">No Existen Registros</option>';
			}else{
			for ($x=0;$x<count($CBresult_bus);$x++)
	    		$combo[] = array($CBresult_bus[$x][0],$CBresult_bus[$x][1]);

			echo $pintar->ContenidoCombo($combo,'null');
			}
		//}
		
	}
	
	public function combosectorhtmlAction(){
		//$this->_helper->getHelper ( 'ajaxContext' )->initContext ();
		
		//if ($this->getRequest ()->isXmlHttpRequest ()) {
			$this->_helper->viewRenderer->setNoRender ();
			$this->_helper->layout->disableLayout ();
			
			$codigo = $_GET["codigo"];
			//$codigo = $this->_request->getPost('codigo');
			$cn = new Model_Data();
			$parameter[]=array("@pcod_sector",'');
			$parameter[]=array("@pdesc_sector",'');
			$parameter[]=array("@pest_sector",'1');
			$parameter[]=array("@pcod_almacen",$codigo);
			/*@pcod_sector
			@pdesc_sector
			@pest_sector
			@pcod_almacen*/	
			$result_bus = $cn ->ejec_store_procedura_sql("MSector_list", $parameter);
			$pintar = New Libreria_Pintar();
			if (count($result_bus)!=0){
			for ($x=0;$x<count($result_bus);$x++)
    			$cbo[] = array($result_bus[$x][0],$result_bus[$x][3]);
			
			echo $pintar->ContenidoCombo($cbo,'null');
			}else{
				echo "<option value='99999'>Seleccionar..</option>";
			}
		//}
	}
	
	public function combolugaralmacenhtmlAction(){
		//$this->_helper->getHelper ( 'ajaxContext' )->initContext ();
		
		//if ($this->getRequest ()->isXmlHttpRequest ()) {
			$this->_helper->viewRenderer->setNoRender ();
			$this->_helper->layout->disableLayout ();
			$codigo = $_GET["codigo"];
			//$codigo = $this->_request->getPost('codigo');
			$cn = new Model_Data();
			$parameter[]=array("@pcod_lugalm",'');
			$parameter[]=array("@pdesc_lugalm",'');
			$parameter[]=array("@pdesc_tiplugar",'');
			$parameter[]=array("@pest_lugalm",'1');
			$parameter[]=array("@pcod_sector",$codigo);
			/*@pcod_sector
			@pdesc_sector
			@pest_sector
			@pcod_almacen*/	
			$result_bus = $cn ->ejec_store_procedura_sql("MLugarAlmacenamiento_list", $parameter);
			$pintar = New Libreria_Pintar();
			if (count($result_bus)!=0){
			for ($x=0;$x<count($result_bus);$x++)
    			$cbo[] = array($result_bus[$x][0],$result_bus[$x][5]);
			
			echo $pintar->ContenidoCombo($cbo,'null');
			}else{
				echo "<option value='99999'>Seleccionar..</option>";
			}
		//}
	}
	
	public function combodivisionhtmlAction(){
		//$this->_helper->getHelper ( 'ajaxContext' )->initContext ();
		
		//if ($this->getRequest ()->isXmlHttpRequest ()) {
			$this->_helper->viewRenderer->setNoRender ();
			$this->_helper->layout->disableLayout ();
			$codigo = $_GET["codigo"];
			//$codigo = $this->_request->getPost('codigo');
			$cn = new Model_Data();
			$parameterdt[]=array("@pcod_divi",'');
			$parameterdt[]=array("@pdesc_divi",'');
			$parameterdt[]=array("@pest_divi",'1');
			$parameterdt[]=array("@pcod_lugalm",$codigo);
			
			$result_det = $cn ->ejec_store_procedura_sql("MDivision_list", $parameterdt);
			$pintar = New Libreria_Pintar();
			if (count($result_det)!=0){
			for ($x=0;$x<count($result_det);$x++)
    			$cbo[] = array($result_det[$x][0],$result_det[$x][2]);
			
			echo $pintar->ContenidoCombo($cbo,'null');
			}else{
				echo "<option value='99999'>Seleccionar..</option>";
			}
		//}
	}
}

